import service from '@/utils/request'
import {CommentsItem, CommentsForm} from '@/api/comment/type'
// import { createService } from '@/utils/request'
import { AxiosResponse } from 'axios'
import qs from 'qs'
import {reqLoginForm} from "@/api/user/type";
import {
    ArrangeExamItem,
    ChooseCourseItem,
    pageQuery,
    reqTeaRegister,
    StusCourseItem,
    TeacherLoginForm
} from "@/api/teacher/type";
import {UnwrapNestedRefs} from "vue";
import {reqMajorInfo} from "@/api/system/type";

enum API{
    TeacherLoginURL = '/teach-system/teacher/login',
    getTeacherInfoURL = '/teach-system/teacher/get-teacher-info',
    // getCoursesByTeacherIdURL = `/teach-system/teacher/${teacherId}`,
    // StuNameListByCourseURL = '/teach-system/teacher/studentsList/{courseId}',
    addScoreURL = '/teach-system/choose-course/give-score/{chooseCourseId}/{score}',
    pageStusURL = '/teach-system/teacher/studentsPageList',
    StuStusScoreByTeacherURL = '/teach-system/teacher/findStusScore',
    pageScoreURL = '/teach-system/teacher/page-score',
    arrangeExamURL = '/teach-system/teacher/arrangeExam',
    teacherGetStuInfo = '/teach-system/teacher/teacherGetStuInfo/{courseId}/{studentName}',
    teaRegisterURL = '/teach-system/teacher/register'
}

//教师登录
export const teacherLogin = (data: reqLoginForm) => {
    return service.teachService.post<any,AxiosResponse<any>>(
        API.TeacherLoginURL,
        data,
    )
}

//获取教师个人信息
export const getTeacherInfo = () => {
    return service.teachService.get<any,AxiosResponse<any>>(
        API.getTeacherInfoURL
    )
}
//教师查看所授课程
export const getAllCourses = (teacherId: number) => {
    const url = `/teach-system/teacher/${teacherId}`
    return service.teachService.get<any, AxiosResponse<any>> (
        url
    )
}

//教师查看该课程下的学生名单
export const findStuNameList = (courseId: number) => {
    const url = `/teach-system/teacher/studentsList/${courseId}`
    return service.teachService.get<any, AxiosResponse<any>> (
        url
    )
}

//教师录入成绩
export const addScoreToStudents = (chooseCourseId: number, score: number) => {
    const url = `/teach-system/choose-course/give-score/${chooseCourseId}/${score}`
    return service.teachService.get<any, AxiosResponse<any>>(
        url
    )
}

//教师查看成绩
export const stusScoreByTeacher = (data: StusCourseItem) => {
    return service.teachService.post<any,AxiosResponse<any>>(
        API.StuStusScoreByTeacherURL,
        data
    )
}

//搜索学生
export const searchStuInfo = (courseId: number, studentName: string) => {
    // const url = `/teach-system/teacher/teacherGetStuInfo/${studentId}`
    return service.teachService.get<any, AxiosResponse<any>>(
        API.teacherGetStuInfo
            .replace('{courseId}', courseId)
            .replace('{studentName}', studentName)
    )
}

//考试安排
export const arrangeExam = (data: ArrangeExamItem) => {
    return service.teachService.post<any,AxiosResponse<any>>(
        API.arrangeExamURL,
        data
    )
}

//教师注册
export const teaRegister = (data:reqTeaRegister) => {
    return service.teachService.post<any,AxiosResponse<any>>(
        API.teaRegisterURL,
        data
    )
}

//录入成绩
export const addScore = (chooseCourseId: number, score: number) => {
    // const url = `/teach-system/teacher/teacherGetStuInfo/${studentId}`
    return service.teachService.get<any, AxiosResponse<any>>(
        API.addScoreURL
            .replace('{chooseCourseId}', chooseCourseId)
            .replace('{score}', score)
    )
}

//分页查看学生名单
export const pageStuQuery = (data: pageQuery) => {
    return service.teachService.post<any,AxiosResponse<any>>(
        API.pageStusURL,
        data
    )
}
// //获取所有专业信息
// export const getAllMajor = (data:reqMajorInfo)=> {
//     return service.teachService.get<any,AxiosResponse<any>>(
//         API.getAllMajorURL + '?' +qs.stringify(data)
//     )
// }
